package newsrecommendation.datamodel.keywords;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Andrea
 */
public class NewsKeywords {

    private List<Double> activeKeywords;

    public NewsKeywords(String csv_Keywords) {
        activeKeywords = new ArrayList();
        for (int i = 0; i < Keywords.get().getSize(); i++) {
            activeKeywords.add(0.0);
        }
        setKeywords(csv_Keywords);
    }

    private void setKeywords(String csv_Keywords) {
        String[] strKeywords = csv_Keywords.split(",");
        for (int i = 0; i < strKeywords.length; i++) {
            String keyword = strKeywords[i];
            int position = Keywords.get().getKeywordPosition(keyword);
            if (position != -1) {
                activeKeywords.set(position, 1.0);
            }
        }
    }

    public List<Double> getActivatedKeywords() {
        return activeKeywords;
    }

    //TODO - BORRAR
    public String getActivatedKeywordsString() {
        String all = "";
        for (int i = 0; i < activeKeywords.size(); i++) {
            if (activeKeywords.get(i) == 1.0) {
                all = all + Keywords.get().getAllKeywords().get(i) + ",";
            }
        }
        return all;
    }
}
